﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Classes
{
    class Searcher
    {
        IList<City> airports;
        IList<City> visited;
        IGraphImpl graph;
        //here I have some fields to work on our own data, of course we will get it rom 
        City aalborg;
        City copenhagen;
        City aarhus;
        City berlin;
        City budapest;
        City sofia;
        City warsaw;
        City vilnus;
        City madrid;
        City moscow;
        City tbilisi;
        City astana;
        public Searcher()
        {
            airports = new List<City>();
            aalborg = new City("Aalborg", "Denmark");
            copenhagen = new City("Copenhagen", "Denmark");
            aarhus = new City("Aarhus", "Demnark");
            berlin = new City("Berlin", "Germany");
            budapest = new City("Budapest", "Romania");
            sofia = new City("Sofia", "Bulagria");
            warsaw = new City("Warsaw", "Poland");
            vilnus = new City("Vilnus", "Lithuania");
            madrid = new City("Madrid", "Spain");
            moscow = new City("Moscow", "Russia");
            tbilisi = new City("Tblisi", "Georgia");
            astana = new City("Astana", "Kazakhstan");

            visited = new List<City>();

            graph = new GraphImpl();


            graph.AddCity(aalborg);
            graph.AddCity(copenhagen);
            graph.AddCity(aarhus);
            graph.AddCity(berlin);
            graph.AddCity(budapest);
            graph.AddCity(sofia);
            graph.AddCity(warsaw);
            graph.AddCity(vilnus);
            graph.AddCity(madrid);
            graph.AddFlight(aalborg, copenhagen);
            graph.AddFlight(aarhus, copenhagen);
            graph.AddFlight(copenhagen, aalborg);
            graph.AddFlight(copenhagen, aarhus);
            graph.AddFlight(copenhagen, berlin);
            graph.AddFlight(aalborg, berlin);
            graph.AddFlight(berlin, moscow);
            graph.AddFlight(moscow, tbilisi);
            graph.AddFlight(tbilisi, astana);
            graph.AddFlight(berlin, copenhagen);
            graph.AddFlight(berlin, budapest);
            graph.AddFlight(berlin, warsaw);
            graph.AddFlight(warsaw, berlin);
            graph.AddFlight(budapest, berlin);
            graph.AddFlight(sofia, budapest);
            graph.AddFlight(berlin, sofia);
            graph.AddFlight(warsaw, vilnus);
            graph.AddFlight(vilnus, warsaw);
            graph.AddFlight(vilnus, berlin);
            graph.AddFlight(berlin, astana);
            graph.AddFlight(madrid, berlin);
            graph.AddFlight(berlin, madrid);
            graph.AddFlight(madrid, sofia);
            graph.AddFlight(budapest, sofia);
            graph.AddFlight(astana, budapest);
            graph.AddFlight(berlin, aalborg);
            graph.AddFlight(warsaw, madrid);
        
        
        
        }
        public void makeASearchInGraph()
        {

            ListOfConnections listOfConnections = new ListOfConnections();
            
              graph.SetTheCityFrom(aalborg);
              graph.SetTheCityTo(copenhagen);
              visited.Add(aalborg);
              listOfConnections = graph.BreadthFirst(visited);
            foreach(Connection connection in listOfConnections.GetConnectionList())
            {
                Console.WriteLine("****************************");

                foreach(Flight f in connection.FlightList())
                {
                    Console.WriteLine(f.From.Name + " ---> " + f.To.Name);
                }

            }
        

        }
    }
}











































/*

 * 
 * 
 *     graph.SpanTreeOfFlightsInBfs(aalborg);
            Console.WriteLine("*********************************************************************");
                        Console.WriteLine("*********************************************************************");
                                        Console.WriteLine("*********************************************************************");
            Console.WriteLine("*********************************************************************");
            Console.WriteLine("*********************************************************************");

            foreach(Flight f in graph.SpanTreeOfFlightsInBfs(aalborg))
            {
                Console.WriteLine(f.From.Name + " ----> " + f.To.Name);
            }
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
  IList<Flight> list = graph.GetSpanTree(aalborg);
            graph.AddSpanTreeToTheConnection(list);
            Connection connection = graph.ReturnConnection();
           connection.PurifyFlights(sofia);
            foreach(Flight f in connection.FlightList())
            {
                Console.WriteLine(f.From.Name + " ----> " + f.To.Name);
            }


        Console.ReadLine();


            IList<City> citiesFromSpan = connection.GetParentsOfThisCity(sofia);
            foreach (City c in citiesFromSpan)
            {
                Console.WriteLine(c.Name);
            }   



IList<Flight> list = graph.GetSpanTree(aalborg);
            foreach (City v in graph.ReturnCityList())
            {
                v.Mark = false;
            }
            IList<City> citiesList = graph.SpanTreeCities(aalborg);
            graph.AddSpanTreeToTheConnection(list, citiesList);

            Connection connection = graph.ReturnConnection();

            IList<City> citiesInTheConnection = connection.CitiesList();
            connection.PurifyFlights();
            
            Console.ReadLine();
            foreach (City c in citiesInTheConnection)
            {
                Console.WriteLine(c.Name);
                foreach(Flight x in  c.Flights())
                {
                    Console.WriteLine(x.From.Name + " ----> " + x.To.Name  + " "  + x.Found.ToString());

                }
            }





/*
 *
 * 
 * 
 * 
 * 
 *             
            foreach (City f in graph.SpanTreeCities(aalborg))
{
    Console.WriteLine(f.Name);
}
This is what fuckin works
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
  IList<Flight> flightsList = graph.GetSpanTree(aalborg);
            IList<City> citiesList = graph.SpanTreeCities(aalborg);


            graph.AddSpanTreeToTheConnection(flightsList, citiesList);
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 *             IList<City> cityList = graph.SpanTreeCities(aalborg);


    foreach (City f in cityList)
    {
        Console.WriteLine(f.Name);
    }
        
    IList<Flight> flightList = graph.GetSpanTree(aalborg);
    foreach (Flight f in flightList)
    {
        Console.WriteLine(f.From.Name + " ----> " + f.To.Name);
    }
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
             
             
             
 * 
 * 
 * 
 * 
 * 
 * IList<Flight> list = graph.GetSpanTree(aalborg);
IList<City> citiesList = graph.SpanTreeCities(aalborg);
graph.AddSpanTreeToTheConnection(list, citiesList);

Connection connection = graph.ReturnConnection();

IList<Flight> flightsInConnection = connection.FlightList();
IList<City> citiesInTheConnection = connection.CitiesList();
 */




//   graph.SpanTreeCities(aalborg);
            
        //  IList<City> listOfCitiesInGraph = new List<City>();
       //   listOfCitiesInGraph = graph.SpanTreeCities(aalborg);\


        /*
         *             foreach (City c in citiesList)
        {
            Console.WriteLine(c.Name);
        }
            
         * 
         * 
       ListOfConnections listOfConnections = graph.FindConnections(aalborg, astana);
       IList<Connection> connectionList = listOfConnections.GetConnectionList();
        foreach(Connection c in connectionList)
     {
         Console.WriteLine("*************************************************");
         foreach (Flight f in c.FlightList())
         {
             Console.WriteLine(f.From.Name + " ----> " + f.To.Name);
         }

      } 
       //   graph.MakeASequenceOfCitiesFromASequenceOfCities(listOfCitiesInGraph);
            
            
        */

        //graph.GetSpanTree(madrid);
            //graph.GetCitiesConnection(aalborg);
        /*  foreach (Flight flight in graph.GetASpanTreesFlights(aarhus, sofia))
          {
              Console.WriteLine(flight.From.Name + " --> " + flight.To.Name);

         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         *    IList<Flight> list = graph.GetSpanTree(aalborg);
          graph.AddSpanTreeToTheConnection(list);
          Connection connection = graph.ReturnConnection();
          foreach(Flight f in connection.FlightList())
          {
              Console.WriteLine(f.From.Name + " ----> " + f.To.Name);

          }
         */
    
                
            //graph.Dfs(aalborg);

       
        //here is the method that should take a result of search.
       //in my opinion we should make a method in class GraphImpl that will be taking the data from a results of DFS 
      //and retreive a list of cities and filghts that will be used to create object of Connection class
     //   public void searchForConnections(City from, City to)
   //     {
            //makeASearchInGraph();
          //  ListOfConnections listOfConnections = new ListOfConnections();
        //}
        
    
     

        /*
        Flight alc = new Flight(aalborg, copenhagen);
        Flight arc = new Flight(aarhus, copenhagen);
        Flight cal = new Flight(copenhagen, aalborg);
        Flight car = new Flight(copenhagen, aarhus);
        Flight cbe = new Flight(copenhagen, berlin);
        Flight albe = new Flight(aalborg, berlin);
        Flight bec = new Flight(berlin, copenhagen);
        Flight bebu = new Flight(berlin, budapest);
        Flight bew = new Flight(berlin, warsaw);
        Flight web = new Flight(warsaw, berlin);
        Flight bube = new Flight(budapest, berlin);
        Flight sbu = new Flight(sofia, budapest);
        Flight bus = new Flight(budapest, sofia);
        Flight sbe = new Flight(sofia, berlin);
        Flight bes = new Flight(berlin, sofia);
        Flight wv = new Flight(warsaw, vilnus);
        Flight vw = new Flight(vilnus, warsaw);
        Flight vbe = new Flight(vilnus, berlin);
        Flight bev = new Flight(berlin, vilnus);
        Flight mbe = new Flight(madrid, berlin);
        Flight bem = new Flight(berlin, madrid);
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         * 
         
             /* Later we will put here some code that will get the info about the graph data from database but for now
        * I'll have my own data
        * */
/*
        City aalborg = new City("Aalborg", "Denmark");
        City copenhagen = new City("Copenhagen", "Denmark");
        City aarhus = new City("Aarhus", "Demnark");
        City berlin = new City("Berlin", "Germany");
        City budapest = new City("Budapest", "Romania");
        City sofia = new City("Sofia", "Bulagria");
        City warsaw = new City("Warsaw", "Poland");
        City vilnus = new City("Vilnus", "Lithuania");
        City madrid = new City("Madrid", "Spain");
        City moscow = new City("Moscow", "Russia");
        City tbilisi = new City("Tblisi", "Georgia");
        City astana = new City("Astana", "Kazakhstan");


         graph = new GraphImpl();
        /* we will have some for each loop here to create graph with flights and edges and cities but for now I will do it manually
         * */

      /*  graph.AddCity(aalborg);
        graph.AddCity(copenhagen);
        graph.AddCity(aarhus);
        graph.AddCity(berlin);
        graph.AddCity(budapest);
        graph.AddCity(sofia);
        graph.AddCity(warsaw);
        graph.AddCity(vilnus);
        graph.AddCity(madrid);
        graph.AddFlight(aalborg, copenhagen);
        graph.AddFlight(aarhus, copenhagen);
        graph.AddFlight(copenhagen, aalborg);
        graph.AddFlight(copenhagen, aarhus);
        graph.AddFlight(copenhagen, berlin);
        graph.AddFlight(aalborg, berlin);
        graph.AddFlight(berlin, moscow);
        graph.AddFlight(moscow, tbilisi);
        graph.AddFlight(tbilisi, astana);
        graph.AddFlight(berlin, copenhagen);
        graph.AddFlight(berlin, budapest);
        graph.AddFlight(berlin, warsaw);
        graph.AddFlight(warsaw, berlin);
        graph.AddFlight(budapest, berlin);
        graph.AddFlight(sofia, budapest);
        graph.AddFlight(berlin, sofia);
        graph.AddFlight(warsaw, vilnus);
        graph.AddFlight(vilnus, warsaw);
        graph.AddFlight(vilnus, berlin);
        graph.AddFlight(berlin, vilnus);
        graph.AddFlight(madrid, berlin);
        graph.AddFlight(berlin, madrid);
        graph.AddFlight(budapest, sofia);
    }
        public void createTheGraph()
        {
           
            

            graph.Dfs(aalborg);

        }
          
         
        */